package com.aaa.pe.service.impl;

import com.aaa.common.entity.Book;
import com.aaa.common.entity.Personinfo;
import com.aaa.pe.dao.PersoninfoDao;
import com.aaa.pe.service.BookService;
import com.aaa.pe.service.PersoninfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Personinfo)表服务实现类
 *
 * @author makejava
 * @since 2020-07-23 14:40:03
 */
@Service("personinfoService")
public class PersoninfoServiceImpl implements PersoninfoService {
    @Autowired
    private PersoninfoDao personinfoDao;
    @Autowired
    private BookService bookService;

    @Override
    public List<Personinfo> selectAll() {
        return personinfoDao.selectAll();
    }

    @Override
    public List<Book> selectBook() {
        return bookService.selectBook();
    }

    /**
     * 通过ID查询单条数据
     *
     * @param personId 主键
     * @return 实例对象
     */
    @Override
    public Personinfo queryById(Integer personId) {
        return this.personinfoDao.queryById(personId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Personinfo> queryAllByLimit(int offset, int limit) {
        return this.personinfoDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param personinfo 实例对象
     * @return 实例对象
     */
    @Override
    public Personinfo insert(Personinfo personinfo) {
        this.personinfoDao.insert(personinfo);
        return personinfo;
    }

    /**
     * 修改数据
     *
     * @param personinfo 实例对象
     * @return 实例对象
     */
    @Override
    public Personinfo update(Personinfo personinfo) {
        this.personinfoDao.update(personinfo);
        return this.queryById(personinfo.getPersonId());
    }

    /**
     * 通过主键删除数据
     *
     * @param personId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer personId) {
        return this.personinfoDao.deleteById(personId) > 0;
    }
}